home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 151-175 / scopedisk170 / postscriptfiles / escher2.ps < prev    next >
Text File  |  1995-03-19  |  10KB  |  320 lines

  1. %!
  2. % Just in case anyone has an idle printer I am posting a close replication of 
  3. % "Square-limit" by M.C.Escher.  I have called it "Square-recursion" because it
  4. % builds the image by recursion, following the triangle subdivision used by 
  5. % Escher.
  6. % I have used Postscript graphics to the full, using transformations and curves
  7. % freely. However it takes a long time to run as a result.  The version posted
  8. % has a variable "Maxlevel", which defaults to 0, and takes 2 minutes to
  9. % produce a core picture.  Try that first, and check that all is well,  then
  10. % if you wish the full gory detail set Maxlevel to 3, and wait 25 minutes (on
  11. % an Apple laser writer).
  12. % Any tips on improving the run time would be welcome.  Have fun.
  13. % John M Pratt,
  14. % European Computer-industry Research Centre,
  15. % Arabellastrasse 17,
  16. % D 8000 Munich 81,
  17. % West Germany.
  18. % email-   harry%ecrcvax.UUCP@Germany.CSNET
  19. %!PS-Adobe-1.0
  20. %%Title:Square-recursion
  21. %%DocumentFonts: (atend)
  22. %%Creator: John Pratt and M.C.Escher 
  23. %%CreationDate:25 November 1987 
  24. %%Pages: (atend)
  25. %%EndComments
  26.  
  27. %%EndProlog
  28.  
  29. %%Page: 1 1 
  30. /Helvetica-Bold findfont 0.5 scalefont setfont 
  31. /level 0 def                %control variable for recursion
  32. /maxlevel 0 def                %Limit of recursion, 3 takes 25 min. 
  33. /Down { /level level 1 add def }def
  34. /Up {/level level 1 sub def} def
  35.  
  36. /Colour  0 def %base colour variable
  37. /Parity 0 def        /Swap {/Parity 0.5 Parity sub def} def
  38. /Odd-colour {/Colour Parity def} def
  39. /Even-Colour {/Colour 0.5 Parity sub def} def 
  40. /White {/Colour 1 def} def 
  41. /Comp {Colour 1 ne {1 setgray} {0 setgray} ifelse} def
  42.  
  43. /cm {28.35 mul} def     /Root2 2 sqrt def    /Invr2 0.5 sqrt def
  44. /HeadMatrix matrix        %create matrix for head triangle
  45.      45 matrix rotate matrix concatmatrix
  46.     Invr2 neg Invr2 matrix scale  matrix concatmatrix
  47.     0 10 matrix translate matrix concatmatrix def    
  48.         %cf 0 10 translate Invr2 neg Invr2 scale 45 rotate 
  49.  
  50. /UpheadMatrix HeadMatrix matrix invertmatrix def
  51.         % cf -45 rotate Root2 neg Root2 scale 0 -10 translate
  52.  
  53. /TailMatrix matrix        %create matrix for tail triangle
  54.       -45 matrix rotate matrix concatmatrix
  55.      Invr2 neg Invr2 matrix scale  matrix concatmatrix
  56.     0 10 matrix translate matrix concatmatrix   def 
  57.         %cf {0 10 translate Invr2 neg Invr2 scale -45 rotate} 
  58.  
  59. /UptailMatrix TailMatrix matrix invertmatrix def
  60.             % cf 45 rotate Root2 neg Root2 scale 0 -10 translate
  61.  
  62. /Op1 matrix          %matrix for duple opposite
  63.     0 -10 matrix translate matrix concatmatrix 
  64.     180 matrix rotate matrix concatmatrix
  65.     0 10 matrix translate matrix concatmatrix def
  66.         
  67. /Downhead {HeadMatrix concat} def          %apply to CTM
  68. /Uphead  {UpheadMatrix concat} def        %apply to CTM
  69. /Downtail {TailMatrix concat}  def          %apply to CTM
  70. /Uptail {UptailMatrix concat} def        %apply to CTM
  71. /Op {Op1 concat} def                 %apply to CTM
  72.  
  73. /DwnR {HeadMatrix transform} def    %applies Head matrix to point
  74. /UpR {UpheadMatrix transform} def    %applies UpHead matrix to point
  75. /DwnL {TailMatrix transform} def    %applies Tail matrix to point
  76. /UpL {UptailMatrix transform} def    %applies UpTail matrix to point
  77. /Opp {Op1 transform} def        %applies opposite matrix to point
  78.  
  79. /Qflip {exch neg exch} def         %Flip by X, X/Y point 180
  80. /Qrot90 {exch neg} def             %rotate X/Y point   -90
  81. /Qrotm90 {neg exch } def         %rotate X/Y point 90
  82. /Qxtran {3 -1 roll add exch} def      %adds top to 3rd, X
  83.  
  84. /A {10 10} def         /A1 {9 8} def          /A2 {7.5 6.2} def
  85. /Ah {A -1 Qxtran -0.5 add } def
  86. /B {6 5.6} def         /B1 {4.8 5} def        /B2 {2.2 4.5} def
  87. /C {0 5} def          /C1 {-1.1 5.3} def    /C2 {-4.2 6} def
  88. /D {B Qrotm90} def      /D1 {A1 Qrotm90} def    /D2 {A2 Qrotm90} def  
  89. /E {A Qrotm90} def    /E1 {A1 DwnL} def     /E2 {A2 DwnL} def
  90. /Eh {Ah Qflip} def
  91. /F {B DwnL} def        /F1 {F 2 Qxtran 2 sub} def     /F2 {-2 7} def
  92. /G {0 7.6} def         /G1 {2 8.2} def        /G2 {3.2 9.5 } def
  93. /Gt {G UpL} def
  94. /H {5.1 10} def        /H1 {6.5 10.5} def    /H2 {8 10.5} def
  95.             /I1 {0 4} def        /I2  {0 2} def 
  96. /J {0 0} def        /J1 {3 0} def        /J2 {3 0} def
  97. /K {C Qrot90} def
  98. /L {C DwnR} def        /L1 {C1 DwnR }def    /L2 {4.7 11} def
  99. /N {0 10.7} def        /N1 {I1 DwnR} def    /N2 {I2 DwnR} def
  100. /Nt {N UpL} def 
  101. /P {L Qflip} def
  102.             /Q1 {4.1 12.4} def    /Q2 {2 13.1} def
  103.  
  104. /a {A1 A2 B} def    /b {B1 B2 C} def 
  105. /c {C1 C2 D} def       
  106. /d {D2 D1 E} def    /e {E1 E2 F} def    
  107. /f {F1 F2 G} def    /fr {F2 UpL F1 UpL F UpL} def
  108. /g {G1 G2 H} def
  109. /h {H1 H2 A} def    /hr {H2 H1 H} def    
  110. /i {I1 I2 J } def    /j {J1 J2 K} def    
  111. /k {C1 Qrot90 C2 Qrot90 B} def    % c with 90 rotate about O
  112. /l {L2 L1 L} def      /lr {L1 L2 H} def    %l reversed
  113. /n {N1 N2 N } def    /ns {I1 I2 N UpR} def     /nm (J M P) def
  114. /o {G} def        /ot {Gt} def         % straight line
  115. /p {I2  Qrot90 I1 Qrot90 C Qrot90} def %ie of tailfish 
  116. /pr {I1 I2 Nt } def     
  117. /q {Q1 Q2 G Opp} def    /s {Comp nm Pup} def    
  118.  
  119. /Fr1 {            %Fish righthand (convex side)
  120.     A  moveto  a  curveto b curveto  c curveto  d curveto 
  121.       } def 
  122.  
  123. /Fr2 {          %Fish righthand for 45 deg angle
  124.     A  moveto  a  curveto b curveto 
  125.     Uphead         %always used in head half
  126.         lr curveto   h curveto    
  127.     Downhead
  128.       } def
  129.  
  130. /Fl1 {             %Fish lefthand (concave side)
  131.     e curveto f curveto   g curveto  h curveto   
  132.       } def
  133.  
  134. /Fl2 {             %Fish lefthand for duple  
  135.     Op         %using opposite fish points
  136.         hr curveto  q curveto 
  137.     Op          %cancelling Op 
  138.     g curveto  h curveto    
  139.       } def
  140.     
  141. /Fc1 {          %Fishcentre inside
  142.     Ah moveto   C C -0.6 Qxtran Eh curveto
  143.       } def
  144.  
  145. /Fc2 {             %Fish centre outside and blunt ends
  146.     Eh -0.05 add lineto  
  147.     C -0.25 add -0.6 Qxtran C -0.25 add Ah -0.05 add curveto
  148.     Ah lineto
  149.       } def
  150.  
  151. /Tailrib1 {newpath -6 9 moveto -5 8 -4 7.3 -2.4 6.9 curveto
  152.     stroke} def
  153. /Tailrib2 {newpath -5.5 6.7 moveto -4.5 6.3  -3.5 6.2 -2.3 6 curveto
  154.     stroke} def
  155. /Tailrib3 {newpath -2.2 7.1 moveto -2.4 6.7  -2.4 6.2 -2.2 5.8 curveto
  156.     stroke} def
  157. /Tailribs  {Tailrib1 Tailrib2 Tailrib3} def
  158.  
  159. /EyeshapeL {newpath -0.4 0.8 moveto 0.7 1.3 1.5 1.2 2.5 0.8 curveto
  160.     1.9  0   1.1 -0.4   0.1 -0.9 curveto
  161.     0  -0.2  -0.1 0.3  -0.4 0.8 curveto closepath} def
  162. /EyeL {gsave  5.6 8.9 translate EyeshapeL 
  163.     Colour 1 ne {fill}{stroke} ifelse grestore} def
  164.  
  165. /EyePupL {   gsave 5.8 9 translate  0.4 0.4 scale  EyeshapeL
  166.     fill grestore } def
  167.  
  168. /EyeshapeR { newpath 0  0.8 moveto 1.4 1.6  1.9 1.6  2.6 1.5 curveto
  169.     2.4 0.8  1.6 0  0.1 -0.8 curveto
  170.     0.1 -0.3 0.1 0.3  0 0.8 curveto closepath } def
  171.  
  172. /EyeR {gsave 5.9 6.7 translate EyeshapeR  
  173.     Colour 1 ne {fill}{stroke} ifelse grestore} def
  174.  
  175. /EyePupR {   gsave 6.1 6.7 translate  0.4 0.4 scale  EyeshapeR 
  176.     fill grestore} def
  177.  
  178. /Pupcol {Colour 1 ne  {Colour setgray } if  } def
  179.  
  180. /Pup    {-3 0 moveto show} def
  181.  
  182. /FishMain {    Comp    %compliment colour
  183.     newpath  Fc1 Fc2  closepath  gsave fill grestore    
  184.     Tailribs
  185.     0.01 setlinewidth  EyeR EyeL 
  186.     Pupcol EyePupR EyePupL } def
  187.  
  188. /Fish { Colour setgray newpath     Fr1 Fl1  closepath  gsave fill grestore
  189.     FishMain } def
  190.  
  191. /Fishd { Colour setgray newpath  Fr1 Fl2  closepath  gsave fill grestore
  192.     FishMain} def
  193.  
  194. /Fish45r {Colour setgray newpath  Fr2 Fl1  closepath    gsave fill grestore
  195.     FishMain } def
  196.   
  197. /Fish45d { Colour setgray newpath  Fr2 Fl2  closepath   gsave fill grestore
  198.     FishMain} def
  199.  
  200. /Ribl {newpath H moveto l curveto  stroke } def
  201. /Ribk {newpath K moveto k curveto  stroke }def
  202. /Ribf {newpath Gt moveto fr curveto stroke } def
  203. /Ribb {newpath B moveto b curveto  stroke } def
  204. /Ribg {newpath G moveto g curveto stroke} def
  205.  
  206. /Wingribs %stack SideRib WingRib Translate-offset Translate-inc Y-Scale-inc
  207.     {4 copy 4 copy         %copy parameters given for 3 ribs
  208.     Comp    0.15 setlinewidth 
  209.     0 1 2 {gsave                  %stack --Wr To Ti Sy Loopv
  210.         dup dup    0.25 mul 0.75 exch sub     %stack ----Sy Lv Lv Sx 
  211.         exch 4 -1 roll mul 0.95 exch sub %stack ---To Ti Lv Sx Sy
  212.             scale              %stack --To Ti Lv
  213.         mul add 0 exch  translate     %stack --Wr 
  214.       cvx exec              %execute WingRibxx
  215.         grestore } for         %stack Sr
  216.       cvx exec } def          %execute Sideribxx
  217.  
  218. /QuadWing { Colour setgray newpath        %wing for quad
  219.     C moveto  i curveto  j curveto   k curveto  b curveto 
  220.     closepath  fill 
  221.     /Ribb /Ribk 0.5  0  0 Wingribs
  222.        } def
  223.  
  224. /TriWing1    { Colour setgray newpath     %wing on Hypoteneuse for triple
  225.     G moveto  g curveto  l curveto   n curveto  o lineto 
  226.     closepath  fill 
  227.     /Ribg /Ribl -0.5 0 0.04 Wingribs  } def
  228.  
  229. /TriWing2 { Colour setgray newpath         %wing on head side for triple
  230.     C moveto  ns curveto  p curveto  k curveto  b curveto
  231.     closepath  fill 
  232.     /Ribb /Ribk 0.5 0.1 0 Wingribs     } def
  233.  
  234. /TriWing3 { Colour setgray  newpath        %wing on tail side for triple
  235.     C moveto  pr curveto   ot lineto   fr curveto  b curveto 
  236.     closepath  fill 
  237.     /Ribb /Ribf 0.8 0.6 0.03 Wingribs    }def
  238.  
  239. /DupleWing {  Colour setgray newpath        %wing for duple
  240.     G moveto  g curveto  q curveto o lineto
  241.     closepath  fill 
  242.     /Ribg /Ribl -0.5 0 0.04 Wingribs }def
  243.  
  244. /Wings0 {QuadWing TriWing1} def 
  245. /Wings1 {TriWing2 TriWing1} def
  246. /Wings2 {TriWing3 TriWing1} def
  247. /Wings3 {TriWing2 DupleWing} def
  248. /Wings4 {TriWing3 DupleWing} def
  249. /Wings5 {QuadWing DupleWing} def    
  250.  
  251. /Headpair {Downhead
  252.            Odd-colour Wings1 Fish45r     %fish Hh
  253.           Down  Sextet   Up      % recurse to smaller level     
  254.       -90 rotate                %Uphead Downtail
  255.          Even-Colour   Wings4 Fishd   
  256.        Uptail             %fish Ht
  257.     } def
  258. /Tailpair {Downhead 
  259.         White Wings3 Fish45d    %fish Th
  260.        -90 rotate            %Uphead    Downtail
  261.            Odd-colour Wings2 Fish   %fish Tt
  262.           Down  Sextet Up     
  263.        Uptail } def
  264.  
  265. /Sextet {level maxlevel le {
  266.     Downhead 
  267.         White  Wings1 Fish45r        %fish H
  268.             Headpair
  269.         -90 rotate                %Uphead+downtail
  270.         Even-Colour  Wings2 Fish          %fish  T
  271.          Tailpair  
  272.         Uptail
  273.      }if} def
  274.  
  275. /RCorner {level maxlevel le {
  276. 20 0 translate 
  277.    Downtail
  278.     Downhead 
  279.          White  Wings5 Fish45d        %fish Th with S wing
  280.     -90 rotate                %Uphead Downtail 
  281.           Odd-colour  Wings0 Fish          %fish Tt
  282.         Down  Sextet RCorner Up
  283.     Uptail 
  284.    Uptail 
  285. -20 0 translate
  286.     }if } def 
  287.  
  288. /LCorner {level maxlevel le {
  289. -20 0 translate 
  290.    Downhead 
  291.     Downtail 
  292.         Even-Colour Wings5 Fishd       %fish Ht with S wing
  293.     90 rotate            %Uptail Downhead
  294.          Odd-colour Wings0 Fish     
  295.         Down  Sextet  LCorner Up
  296.     Uphead
  297.    Uphead
  298. 20 0 translate
  299.     }if } def 
  300.  
  301. /Centre {Odd-colour  Wings0 Fish} def
  302.  
  303. gsave
  304.   10 cm 15 cm translate   
  305.   0.3 cm 0.3 cm scale 0.05 setlinewidth  
  306.   1 setflat 1 setlinecap
  307.   150 45 {0.5 mul add} setscreen
  308. 4 {Centre Sextet RCorner LCorner Swap -90 rotate} repeat s
  309. grestore
  310. showpage
  311.  
  312. %%Trailer
  313. %%Pages: 1 
  314. %%DocumentFonts: Helvetica-Bold
  315.